//
//  DataObject.h
//  iStock Global
//
//  Created by Andy on 2010/10/3.
//  Copyright 2010 __MyCompanyName__. All rights reserved.
//
@protocol DataObjectDelgete

-(void)DelgetestopAnimating;
-(void)StartDrawGraph:(NSUInteger)indexrow isusdNavagarator:(BOOL)usedNavagarator isresetGraphLocation:(BOOL)isResetGraphLocationa; //啓動繪圖功能
-(void)getERRORdownload:(NSString *)symbol;  
-(void)closeCellActivityIndicator:(NSUInteger)indexrow symbol:(NSString *)csymbol; //TableCELL的活動指示器
-(void)ObjectDownload_didFailWithError:(NSError *)error asymbol:(NSString *)symbol;
-(void)afterOptimize;
-(void)afteCaluateTableIndicator;

@end
NSTimeInterval timeIntervalForNumberOfWeeks(float numberOfWeeks);
#import <Foundation/Foundation.h>
#import "DownloadData.h"
#import "DateFormatter.h"
#import "ParaObject.h"
#import "LFcaluateTemp.h"

 

//#import "StockTableQuote.h"

@interface DataObject : NSObject<DownloadDataDelgete> {
	id <DataObjectDelgete> delgete;	
	
	ParaObject *aParaObject;
	 
	//設定日週月
	NSString *dwm;
	
	//網路資料下載物件
	DownloadData *downloadobject;	
	
	NSString *symbol;
	 
	//NSString *code;
	NSString *lastprice;
	NSString *s_open;
	NSString *s_high;
	NSString *s_low;
	
	NSString *tradedate;
	NSString *tradetime;
	NSString *updown;
	NSString *updownPercent;
	NSNumber *activity;
	NSString *his;
	NSString *name;						
	NSString *id_class;	
	
	NSString *volume_yahoo;
	NSString *EPS_Estimate_Current_Year_yahoo; //e7
	NSString *Price_EPS_Estimate_Next_Year_yahoo; //r6	
	
	
	NSNumber *Nupdwon;
	NSNumber *Nupdwonpercent;
	
	//時間序列資料
	
	NSMutableArray *financialData; //股價資料 開收高低成交量資料
	NSMutableArray *financialData_Calcuate; //技術指標資料
	NSMutableArray *financialData_TradeSystem; //單一參數之下記錄每日筆的資料
	NSMutableArray *financialData_TradeSystem_Optimize; //多參數之下記錄每ㄧ參數的損益買賣彙整
	
	//時間序列資料的屬性特徵
	NSDecimalNumber *overallHigh;
    NSDecimalNumber *overallLow;	
	NSDecimalNumber *VoloverallHigh;
    NSDecimalNumber *VoloverallLow;
    //即時資料
	NSDecimalNumber *rHigh;//最高價
    NSDecimalNumber *rOpen;//開盤價	
	NSDecimalNumber *rLow;
    NSDecimalNumber *rClsoe;
	NSDecimalNumber *rVolume;
	NSDecimalNumber *rUpDown;
	NSDecimalNumber *rUpDownRatio;
	NSDate *rDate;
    BOOL getYahooHistroryData_writetofile; //取玩資料之後是否要將檔案寫入檔案
	BOOL getYahooHistroryData_drawChart; //取完資料之後是否要繪圖
    BOOL getYahooHistroryData_closeCellActivityIndicator; //取玩資料是否要順便關閉TableCELL的活動指示器
	BOOL getYahooHistroryData_isuse_navcontroller; //是否要用navcontroller
	BOOL getYahooHistroryData_resetGraphLocation; //繪圖時是否要重新Ｒeset位置資訊
	BOOL getYahooHistroryData_isOptimizeTradeSystem; //是否進行最佳化	
	BOOL getYahooHistroryData_isCaluateTableIndicator; //是否進行報價表上的指標運算	
	
	BOOL BoolIsUsexxTradexxForBackUpData;
	NSString *symbol_xxtradexx;
	
	NSUInteger graph_index;
	
	int numberofweeks;
	
	//計算欄位
	NSString *Finance_count;
	NSString *ChangePercent10day;
	NSString *ChangePercent5day;	
	NSString *ChangePercent20day;
	NSString *ChangePercent60day;	
	NSString *ChangePercent120day;
	NSString *ChangePercent240day;	
	NSString *ChangePercentWeek;
	NSString *ChangePercentMonth;	
	NSString *ChangePercentQuarter;
	NSString *ChangePercentYear;		
	 
	NSString *LF_Signal1;
	NSString *LF_BreakP1;	
	NSString *LF_Signal2;
	NSString *LF_BreakP2;
	NSString *LF_Signal3;
	NSString *LF_BreakP3;	
	
    NSString *LF_Action1;
	NSString *LF_Action2;
	NSString *LF_Action3;	
	
    NSString *cLF_b1;
	NSString *cLF_s1;
    NSString *cLF_bout1;
    NSString *cLF_sout1;	
	NSString *cLF_b2;
	NSString *cLF_s2;
    NSString *cLF_bout2;
    NSString *cLF_sout2;	
	NSString *cLF_b3;
	NSString *cLF_s3;
    NSString *cLF_bout3;
    NSString *cLF_sout3;	
	
	NSString *LF_LongDay1;
	NSString *LF_LongDay2;	
	NSString *LF_LongDay3;
	NSString *LF_ShortgDay1;
	NSString *LF_ShortgDay2;
	NSString *LF_ShortgDay3;		
	
	NSString *LF_LongProfit1;
	NSString *LF_LongProfit2;	
	NSString *LF_LongProfit3;
	NSString *LF_ShortgProfit1;
	NSString *LF_ShortgProfit2;
	NSString *LF_ShortgProfit3;	
	
	NSString *MESA_FAMA1;
	NSString *MESA_MAMA1;
	NSString *MESA_FAMA2;
	NSString *MESA_MAMA2;	
	NSString *MESA_FAMA3;
	NSString *MESA_MAMA3;	
	
	NSString *MESA_bs1;
	NSString *MESA_bs2;
	NSString *MESA_bs3;	
	
	NSString *MESA_Signal1;
	NSString *MESA_Signal2;
	NSString *MESA_Signal3;		
	
	
	NSString *MESA_LongDay1;
	NSString *MESA_LongDay2;	
	NSString *MESA_LongDay3;
	NSString *MESA_ShortgDay1;
	NSString *MESA_ShortgDay2;
	NSString *MESA_ShortgDay3;		
	
	NSString *MESA_LongProfit1;
	NSString *MESA_LongProfit2;	
	NSString *MESA_LongProfit3;
	NSString *MESA_ShortgProfit1;
	NSString *MESA_ShortgProfit2;
	NSString *MESA_ShortgProfit3;		
	
	
	
	NSMutableArray *havetocalcuateTableIndicator;
	
}

@property(assign) id <DataObjectDelgete> delgete;

@property (nonatomic, retain) NSDecimalNumber *overallHigh;
@property (nonatomic, retain) NSDecimalNumber *overallLow;
@property (nonatomic, retain) NSDecimalNumber *VoloverallHigh;
@property (nonatomic, retain) NSDecimalNumber *VoloverallLow;

@property (nonatomic, retain) NSMutableArray *financialData;
@property (nonatomic, retain) NSMutableArray *financialData_Calcuate;
@property (nonatomic, retain) NSMutableArray *financialData_TradeSystem;
@property (nonatomic, retain) NSMutableArray *financialData_TradeSystem_Optimize;

@property (nonatomic, assign) ParaObject *aParaObject;
@property (nonatomic, retain) NSString *symbol_xxtradexx;
@property (nonatomic, copy) NSString *symbol;
@property (nonatomic, copy) NSString *id_class;
@property (nonatomic, copy) NSString *name;
@property (nonatomic, retain) NSString *dwm;


//@property (nonatomic, retain) NSString *code;
@property (nonatomic, copy) NSString *lastprice;
@property (nonatomic, copy) NSString *s_open;
@property (nonatomic, copy) NSString *s_high;
@property (nonatomic, copy) NSString *s_low;



@property (nonatomic, copy) NSString *tradedate;
@property (nonatomic, copy) NSString *tradetime;
@property (nonatomic, copy) NSString *updown;
@property (nonatomic, copy) NSString *updownPercent;
@property (nonatomic, copy) NSNumber *activity;
@property (nonatomic, copy) NSString *his;
@property (nonatomic, copy) NSString *volume_yahoo;
@property (nonatomic, copy) NSString *EPS_Estimate_Current_Year_yahoo; //e7
@property (nonatomic, copy) NSString *Price_EPS_Estimate_Next_Year_yahoo; //r6	


@property (nonatomic, retain) NSNumber *Nupdwon;
@property (nonatomic, retain) NSNumber *Nupdwonpercent;

@property (nonatomic, retain) NSString *Finance_count;
@property (nonatomic, retain) NSString *ChangePercent10day;
@property (nonatomic, retain) NSString *ChangePercent5day;	
@property (nonatomic, retain) NSString *ChangePercent20day;
@property (nonatomic, retain) NSString *ChangePercent60day;
@property (nonatomic, retain) NSString *ChangePercent120day;
@property (nonatomic, retain) NSString *ChangePercent240day;
@property (nonatomic, retain) NSString *ChangePercentWeek;
@property (nonatomic, retain) NSString *ChangePercentMonth;	
@property (nonatomic, retain) NSString *ChangePercentQuarter;
@property (nonatomic, retain) NSString *ChangePercentYear;
//@property (nonatomic, retain) NSString *LF_Signal;
// (nonatomic, retain) NSString *LF_BreakP;
@property (nonatomic, retain) NSString *LF_Signal1;
@property (nonatomic, retain) NSString *LF_BreakP1;
@property (nonatomic, retain) NSString *LF_Signal2;
@property (nonatomic, retain) NSString *LF_BreakP2;
@property (nonatomic, retain) NSString *LF_Signal3;
@property (nonatomic, retain) NSString *LF_BreakP3;


@property (nonatomic, retain) NSString *LF_Action1;
@property (nonatomic, retain) NSString *LF_Action2;
@property (nonatomic, retain) NSString *LF_Action3;

@property (nonatomic, retain) NSString *cLF_b1;
@property (nonatomic, retain) NSString *cLF_s1;
@property (nonatomic, retain) NSString *cLF_bout1;
@property (nonatomic, retain) NSString *cLF_sout1;	
@property (nonatomic, retain) NSString *cLF_b2;
@property (nonatomic, retain) NSString *cLF_s2;
@property (nonatomic, retain) NSString *cLF_bout2;
@property (nonatomic, retain) NSString *cLF_sout2;	
@property (nonatomic, retain) NSString *cLF_b3;
@property (nonatomic, retain) NSString *cLF_s3;
@property (nonatomic, retain) NSString *cLF_bout3;
@property (nonatomic, retain) NSString *cLF_sout3;

@property (nonatomic, retain) NSString *LF_LongDay1;
@property (nonatomic, retain) NSString *LF_LongDay2;	
@property (nonatomic, retain) NSString *LF_LongDay3;
@property (nonatomic, retain) NSString *LF_ShortgDay1;
@property (nonatomic, retain) NSString *LF_ShortgDay2;
@property (nonatomic, retain) NSString *LF_ShortgDay3;	

@property (nonatomic, retain) NSString *LF_LongProfit1;
@property (nonatomic, retain) NSString *LF_LongProfit2;	
@property (nonatomic, retain) NSString *LF_LongProfit3;
@property (nonatomic, retain) NSString *LF_ShortgProfit1;
@property (nonatomic, retain) NSString *LF_ShortgProfit2;
@property (nonatomic, retain) NSString *LF_ShortgProfit3;	

@property (nonatomic, retain) NSString *MESA_FAMA1;
@property (nonatomic, retain) NSString *MESA_MAMA1;
@property (nonatomic, retain) NSString *MESA_FAMA2;
@property (nonatomic, retain) NSString *MESA_MAMA2;	
@property (nonatomic, retain) NSString *MESA_FAMA3;
@property (nonatomic, retain) NSString *MESA_MAMA3;


@property (nonatomic, retain) NSString *MESA_bs1;
@property (nonatomic, retain) NSString *MESA_bs2;
@property (nonatomic, retain) NSString *MESA_bs3;	

@property (nonatomic, retain)  NSString *MESA_Signal1;
@property (nonatomic, retain)  NSString *MESA_Signal2;
@property (nonatomic, retain)  NSString *MESA_Signal3;	


@property (nonatomic, retain) NSString *MESA_LongDay1;
@property (nonatomic, retain) NSString *MESA_LongDay2;	
@property (nonatomic, retain) NSString *MESA_LongDay3;
@property (nonatomic, retain) NSString *MESA_ShortgDay1;
@property (nonatomic, retain) NSString *MESA_ShortgDay2;
@property (nonatomic, retain) NSString *MESA_ShortgDay3;	

@property (nonatomic, retain) NSString *MESA_LongProfit1;
@property (nonatomic, retain) NSString *MESA_LongProfit2;	
@property (nonatomic, retain) NSString *MESA_LongProfit3;
@property (nonatomic, retain) NSString *MESA_ShortgProfit1;
@property (nonatomic, retain) NSString *MESA_ShortgProfit2;
@property (nonatomic, retain) NSString *MESA_ShortgProfit3;	



@property (nonatomic, assign) NSMutableArray *havetocalcuateTableIndicator;
-(void)Caluate_TradeSystem:(NSString *)funct;
//計算技術指標
-(void)Caluate;

//移動均線
-(float)MovingAverage_record:(NSMutableDictionary *)DictRecord 
					 index_i:(int)i 
				  N_Indentfy:(NSString *)identfy
				 P_movingday:(int)movingday 
					 I_close:(float)close ;

-(void)LF_record:(NSMutableDictionary *)DictRecord 
		 index_i:(int)i 
	  N_Indentfy:(NSString *)identfy
	 P_BRangeDay:(int)BRangeDay
	 P_SRangeDay:(int)SRangeDay
		P_Bratio:(float)Bratio
		P_Sratio:(float)Sratio
	  I_average1:(float)average1
	I_average1_1:(float)average1_1
		 I_close:(float)close 
		  I_high:(float)high
		   I_low:(float)low
	   I_close_1:(float)close_1
	   O_LFCtemp:(LFcaluateTemp *)LFcalcuate;

-(void)MESA_record:(NSMutableDictionary *)csvDict
		   index_i:(int)i 
		N_Indentfy:(NSString *)identfy 
		 P_FastLim:(float)FastLim 
		 P_SlowLim:(float)SlowLim
			 fhigh:(float)high
			  flow:(float)low;

- (BOOL)writeToFile:(NSString *)path atomically:(BOOL)flag;
- (NSDictionary *)plistRep;

-(BOOL)getYahooHistroryDatagraphindex:(NSUInteger)aindex 					  
					  writetofile:(BOOL)WriteToFile 
						drawChart:(BOOL)bdrawchart 
	   closeCellActivityIndicator:(BOOL)bcloseCellActivityIndicator 
				 isuseNavagarator:(BOOL)isnavcontroller
			 isresetGraphLocation:(BOOL)aisresetGraphLocation 
						   isOptimize:(BOOL)isOptimizeTradeSystem 
			  isCaluateTableIndicator:(BOOL)isCaluateTableIndicator;
	

//資料寫入檔案方法
-(NSString *)pathForSymbol:(NSString *)aSymbol;
-(BOOL)writeToFile:(NSString *)path atomically:(BOOL)flag;
-(NSDictionary *)plistRep;

-(NSString *)CpathForSymbol:(NSString *)aSymbol;
-(BOOL)CwriteToFile:(NSString *)path atomically:(BOOL)flag;
-(NSDictionary *)CplistRep;

-(void)canceldownload;

-(void)dealloc_financialData;

-(NSString *)faultTolerantPathForSymbol:(NSString *)aSymbol;
-(NSDictionary *)dictionaryForSymbol:(NSString *)aSymbol;
-(void)memoryWithDictionary:(NSDictionary *)aDict targetSymbol:(NSString *)aSymbol ;

-(void)Download_Data:(NSString *)identifier 
		   startDate:(NSDate*)astartDare 
			 endDate:(NSDate *)aendDate;

-(void)afterDownloadYahooData;
-(void)afterDownloadAllHistoryData;
-(void)getYahooAllHistroryData;
-(void)afterDownloadYahooDailyData;
-(void)isUsexxTradexxForBackUpData;
-(int)Date_weekday:(NSDate *)thedate;
-(int)Date_month:(NSDate *)thedate;
-(int)Date_year:(NSDate *)thedate;

-(id)initWithTargetSymbol:(NSString *)aSymbol bname:(NSString *)cname;
NSInteger comparator_WinPercentage( NSMutableDictionary *d1, NSMutableDictionary *d2, void *context );
NSInteger comparator_YearPercentageRealizeGainLoss( NSMutableDictionary *d1, NSMutableDictionary *d2, void *context );
NSInteger comparator_TotalCount( NSMutableDictionary *d1, NSMutableDictionary *d2, void *context );
-(void)Caluate_TableIndicator;
-(void)optimized_write_to_sql:(NSDictionary *)toData dwm:(NSString *)adwm sele012:(NSString *)sele012 tradesystemname:(NSString *)tradesystem ;
-(void)Copy_symbol:(NSString *)obj;
-(void)Copy_tradedate:(NSString *)obj;
-(void)Copy_tradetime:(NSString *)obj;
-(void)Copy_updown:(NSString *)obj;
-(void)Copy_updownPercent:(NSString *)obj;
-(void)Copy_open:(NSString *)obj;
-(void)Copy_high:(NSString *)obj;
-(void)Copy_low:(NSString *)obj;
-(NSMutableArray *)Google_HistoryData_Daily:(NSString *)symbols 
                                 StartDates:(NSString *)ST
                                   EndDates:(NSString *)ED;

-(NSMutableArray *)Google_HistoryData:(NSMutableArray *)google_data 
                               Symbol:(NSString *)symbol_s 
                            StartDate:(NSString *)StartDate_s 
                              EndDate:(NSString *)EndDate_s 
                                  num:(int)num_i 
                                start:(int) start_i ;
-(NSString *)TickerConvert_yahoo_google:(NSString *)yahoo_ticker;

@end
